-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Improve Log4j Core configuration file detection for Log4j 3 #46409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Log4j Core configuration file detection for Log4j 3 #46409
Conversation
Log4j Core 3 has undergone significant modularization and no longer uses optional parser dependencies. This change requires updates to Spring Boot's configuration file detection logic to properly support both Log4j Core 2 and 3. * **Updated configuration file detection** Spring Boot now detects configuration formats based on the presence of `ConfigurationFactory` implementations, instead of relying on optional parser dependencies (as was the case in Log4j Core 2). * **Improved classloader usage for reflection** Reflection logic now uses the classloader that loaded Log4j Core, rather than the one associated with the Spring Boot context, ensuring greater compatibility in modular environments. * **Adjusted configuration file lookup order** The lookup now prioritizes configuration files specified via properties over automatically discovered ones, improving consistency with Log4j Core. * **Support for contextual configuration files** Files named in the form `log4j2<contextName>.<extension>` are now also supported. These changes ensure compatibility with Log4j Core 3 while preserving support for Log4j Core 2, improving Spring Boot's flexibility in detecting and loading user-defined logging configurations. > [!NOTE] > The configuration file detection logic introduced here could potentially be moved into a future version of Log4j Core itself. For more context, see apache/logging-log4j2#3775. Signed-off-by: Piotr P. Karwasz <piotr@github.copernik.eu>
0de4595
to
2c40cad
Compare
Signed-off-by: Piotr P. Karwasz <piotr@github.copernik.eu>
core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java
Show resolved
Hide resolved
Log4j Core 3 has undergone significant modularization and no longer uses optional parser dependencies. This change requires updates to Spring Boot's configuration file detection logic to properly support both Log4j Core 2 and 3. **Updated configuration file detection** Spring Boot now detects configuration formats based on the presence of ConfigurationFactory implementations, instead of relying on optional parser dependencies (as was the case in Log4j Core 2). **Improved classloader usage for reflection** Reflection logic now uses the classloader that loaded Log4j Core, rather than the one associated with the Spring Boot context, ensuring greater compatibility in modular environments. * **Adjusted configuration file lookup order** The lookup now prioritizes configuration files specified via properties over automatically discovered ones, improving consistency with Log4j Core. **Support for contextual configuration files** Files named in the form `log4j2<contextName>.<extension>` are now also supported. These changes ensure compatibility with Log4j Core 3 while preserving support for Log4j Core 2, improving Spring Boot's flexibility in detecting and loading user-defined logging configurations. See gh-46409 Signed-off-by: Piotr P. Karwasz <piotr@github.copernik.eu>
Thanks @ppkarwasz ! |
@mhalbritter thanks a lot for merging this! 💯 For context: this PR was our contingency plan to ensure Spring Boot 4 is fully compatible with Log4j Core 3. From the SB integration’s perspective, the only real breaking change in 3.x is the modularization of configuration factories. In the short term (starting with public Configuration getConfiguration(LoggerContext, String, List<URI>); as discussed in apache/logging-log4j2#3839. We believe this is the key missing piece that currently forces you to depend on so many Log4j Core internals ( Since our project is entirely volunteer-driven, we can’t promise to hit the |
My pleasure. Please let us know when the new API lands and we can see how and in which version we can use it. Thanks! |
Log4j Core 3 has undergone significant modularization and no longer uses optional parser dependencies. This change requires updates to Spring Boot's configuration file detection logic to properly support both Log4j Core 2 and 3.
Summary of Changes
Updated configuration file detection
Spring Boot now detects configuration formats also based on the presence of
ConfigurationFactory
implementations, instead of only relying on optional parser dependencies (as was the case in Log4j Core 2).Improved classloader usage for reflection
Reflection logic now uses the classloader that loaded Log4j Core, rather than the one associated with the Spring Boot context, ensuring greater compatibility in modular environments.
Adjusted configuration file lookup order
The lookup now prioritizes configuration files specified via properties over automatically discovered ones, improving consistency with Log4j Core.
Support for contextual configuration files
Files named in the form
log4j2<contextName>.<extension>
are now also supported.These changes ensure compatibility with Log4j Core 3 while preserving support for Log4j Core 2, improving Spring Boot's flexibility in detecting and loading user-defined logging configurations.
Note
The configuration file detection logic introduced here could potentially be moved into a future version of Log4j Core itself. For more context, see apache/logging-log4j2#3775.